package org.example;

import org.junit.jupiter.api.Test;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Scanner;




// 抽象处理器
abstract class Handler {
    protected Handler nextHandler;

    public void setNextHandler(Handler nextHandler) {
        this.nextHandler = nextHandler;
    }

    public abstract void handleRequest(int request);
}

// 具体处理器1
class ConcreteHandler1 extends Handler {
    @Override
    public void handleRequest(int request) {
        if (request >= 0 && request < 10) {
            System.out.println("ConcreteHandler1 处理请求: " + request);
        } else if (nextHandler != null) {
            nextHandler.handleRequest(request);
        }
    }
}

// 具体处理器2
class ConcreteHandler2 extends Handler {
    @Override
    public void handleRequest(int request) {
        if (request >= 10 && request < 20) {
            System.out.println("ConcreteHandler2 处理请求: " + request);
        } else if (nextHandler != null) {
            nextHandler.handleRequest(request);
        }
    }
}

// 具体处理器3
class ConcreteHandler3 extends Handler {
    @Override
    public void handleRequest(int request) {
        if (request >= 20 && request < 30) {
            System.out.println("ConcreteHandler3 处理请求: " + request);
        } else if (nextHandler != null) {
            nextHandler.handleRequest(request);
        } else {
            System.out.println("没有处理器能处理该请求: " + request);
        }
    }
}


public class Text {


    public static int majorityElement(int[] nums) {
        int x=nums[0];
        int count=1;
        for(int i=1;i<nums.length;i++){
            if(count==0){
                x=nums[i];
            }
            if(nums[i]==x){
                count++;
            }else{
                count--;
            }
        }
        return x;
    }


    static volatile boolean stop = false;


    public static void main(String[] args) {

        int a=majorityElement(new int[]{2,3,3,3,2,2,2});
        System.out.println(a);


    }




}
